// pages/index1/index1.js

var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    plain: false,
    disabled: false,
    dlzh: '',
    dlma: '',
    wxid: ''
  },

  /**
   * 生命周期函数--监听页面加载 
   */
  onLoad: function () {
    var wxid = wx.getStorageSync('openid');
    this.setData({
      wxid: wxid
    })
  },

  //输入账号
  dlzhinput: function (e) {
    this.setData({
      dlzh: e.detail.value
    })
  },

  //输入账号
  dlmainput: function (e) {
    this.setData({
      dlma: e.detail.value
    })
  },


  //账号登录
  uaccountlogin: function (e) {
    var dlzh = this.data.dlzh;
    var dlma = this.data.dlma;
    if (dlzh == '') {
      wx.showModal({
        title: '友情提示',
        content: '请输入账号!',
        showCancel: !1,
      })
      return;
    }

    if (dlma == '') {
      wx.showModal({
        title: '友情提示',
        content: '请输入密码!',
        showCancel: !1,
      })
      return;
    }
    var wxid = this.data.wxid;
    var djson = {
      wxid: wxid,
      dlzh: dlzh,
      dlma: dlma
    };

    wx.showLoading({
      title: '登录中,请等待......',
    })

    var that = this;
    that.setData({
      disabled: true,
      loading: true
    })

    wx.request({
      url: app.myUlife.ulifeUrl + '/wechart/wechartUaccountlogin.html',//请求地址
      data: djson,
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          disabled: false,
          loading: false
        })
        if (res.data.result){
            //登录成功
          var usrinfo = res.data;
          wx.setStorageSync('user_type', usrinfo.user_type);

          //1学生 2教师
          if (usrinfo.user_type == "1") {
            if (usrinfo.stusize && usrinfo.stusize != "1") {
              that.setData({
                stus: usrinfo.stus
              });
              //有多个孩子，选择其中一个登陆
              wx.navigateTo({
                url: '../../pages/qhdl/qhdl'
              })
            }else{
              wx.setStorageSync('name', usrinfo.name);
              wx.setStorageSync('identity', usrinfo.identity);
              wx.setStorageSync('nj', usrinfo.nj);
              wx.setStorageSync('bj', usrinfo.bj);
              wx.setStorageSync('usid', usrinfo.usid);
              wx.setStorageSync('dlzh', usrinfo.dlzh);
              wx.setStorageSync('sex', usrinfo.sex);
              wx.switchTab({
                url: '../../pages/home/home'
              })
            }
          }else{
            wx.setStorageSync('name', usrinfo.name);
            wx.setStorageSync('identity', usrinfo.identity);
            wx.setStorageSync('nj', usrinfo.nj);
            wx.setStorageSync('bj', usrinfo.bj);
            wx.setStorageSync('usid', usrinfo.usid);
            wx.setStorageSync('dlzh', usrinfo.dlzh);
            wx.setStorageSync('sex', usrinfo.sex);
            wx.switchTab({
              url: '../../pages/home/home'
            })
          }  
        }else{
          wx.showModal({
            title: '友情提示',
            content: res.data.msg,
            showCancel: !1,
          })
        }

       
      }
    })
    
  },



})
